package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.api.dto.ImparityGoodsDto;
import com.sale.goods.api.vo.GetDataByCodeGoodsVo;
import com.sale.goods.domain.dto.GoodsDisburseDto;
import com.sale.goods.domain.dto.ReceiptAndPaymentDocDto;
import com.sale.goods.domain.vo.GoodsDisburseVo;
import com.sale.goods.domain.vo.GoodsIncomeVo;
import com.sale.goods.service.IGoodsDisburseService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 其他支出单
 * @Date 23-08-07
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/disburse")
public class GoodsDisburseController extends BaseController {

    private final IGoodsDisburseService goodsDisburseService;

    /**
     * 获取其他支出单
     */
    //@SaCheckPermission("finance:expenditure:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsDisburseDto> list(GoodsDisburseVo goodsDisburseVo, PageQuery pageQuery)
    {
        return goodsDisburseService.selectDisburseList(goodsDisburseVo,pageQuery);
    }

    /**
     * 获取其他支出单 (弹框)
     */
    @GetMapping("/listPop")
    public TableDataInfo<ReceiptAndPaymentDocDto> listPop(GoodsDisburseVo goodsDisburseVo, PageQuery pageQuery)
    {
        return goodsDisburseService.selectDisbursePopList(goodsDisburseVo,pageQuery);
    }


    /**
     * 新增其他支出单
     */
    //@SaCheckPermission("finance:expenditure:add")
    @Log(title = "其他支出单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsDisburseVo goodsDisburseVo) throws Exception {
        return toAjax(goodsDisburseService.insertDisburse(goodsDisburseVo));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("finance:expenditure:query")
    @GetMapping(value = "/{DisburseId}")
    public R getInfo(@PathVariable long DisburseId)
    {
        return R.ok(goodsDisburseService.selectDisburseById(DisburseId));
    }

    /**
     * 删除收款单
     */
    //@SaCheckPermission("finance:expenditure:remove")
    @Log(title = "其他支出单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{DisburseId}")
    public R<Void> remove(@PathVariable("DisburseId") Long DisburseId) {
        return toAjax(goodsDisburseService.deleteDisburseById(DisburseId));
    }

    /**
     * 修改收款单
     */
    //@SaCheckPermission("finance:expenditure:edit")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsDisburseVo goodsDisburseVo) {
        return toAjax(goodsDisburseService.updateDisburseEdit(goodsDisburseVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:expenditure:subExamine")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{DisburseId}")
    public R<Void> submitReview(@PathVariable("DisburseId") Long DisburseId) {
        return toAjax(goodsDisburseService.submitReview(DisburseId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:expenditure:revoke")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{DisburseId}")
    public R<Void> deleteReview(@PathVariable("DisburseId") Long DisburseId) {
        return toAjax(goodsDisburseService.deleteReview(DisburseId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:expenditure:examine")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsDisburseVo goodsDisburseVo) throws Exception {
        return toAjax(goodsDisburseService.goodSExamineReview(goodsDisburseVo));
    }

    /**
     * 财务-核销单 通过获取未全部核销的其他支出单数据
     */
    @GetMapping("/getNoVerificationList")
    public List<ImparityGoodsDto> getNoVerificationList(GetDataByCodeGoodsVo getDataByCodeVo) {
        return goodsDisburseService.getNoVerificationList(getDataByCodeVo);
    }

}
